package com.nowcoder.community.util;

import com.mysql.cj.util.StringUtils;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;


public class CookieUtil {
    public static String getValue(HttpServletRequest request, String name) {
        if (request==null || StringUtils.isNullOrEmpty(name)) {
             throw new IllegalArgumentException("参数不能为空");
        }
        Cookie[] cookies =request.getCookies();
        if (cookies !=null) {
            for (Cookie cookie :cookies) {
                if (cookie.getName().equals(name)) {
                    return cookie.getValue();
                }
            }
            return null;
        }
        return null;
    }
}
